﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    class DbHelper
    {   /// <summary>
    /// 添加新表
    /// </summary>
        private static readonly string connectionString = "server=LAPTOP-CUC47BVA\\SQLEXPRESS;database=Blogs;uid=sa;pwd=zcq.13870613279";
        public static DataTable GetDataTable(string table)
        {
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(table, sqlConnection);

            DataTable dataTable = new DataTable();

            sqlConnection.Open();

            sqlDataAdapter.Fill(dataTable);

            return dataTable;
        }
       ////添加或者修改方法///
        public static   int AddOrDelete(string table)
        {   
            SqlConnection sqlConnection = new SqlConnection(connectionString);

            SqlCommand sqlCommand = new SqlCommand(table, sqlConnection);

            sqlConnection.Open();

            return sqlCommand.ExecuteNonQuery();
        }

    }
}
